www.gusucode.com > VC++网络版的打字软件源程序-源码程序 > VC++网络版的打字软件源程序-源码程序\code\TypeClt V2.0\TypeDoc.cpp

    //Download by http://www.NewXing.com
// TypeDoc.cpp : implementation of the CTypeDoc class
//

#include "stdafx.h"
#include "Type.h"
#include "TypeDoc.h"

#include "LoginDlg.h"
#include "InputDlg.h"

#include "MainView.h"
#include "ScoreView.h"

#include "KeyWordView.h"
#include "TypeView.h"
#include "NetTypeTestView.h"

#include "SocketInfo.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define PORT_DEFAULT	62248	//定义端口

/////////////////////////////////////////////////////////////////////////////
// CTypeDoc

IMPLEMENT_DYNCREATE(CTypeDoc, CDocument)

BEGIN_MESSAGE_MAP(CTypeDoc, CDocument)
	//{{AFX_MSG_MAP(CTypeDoc)
	ON_COMMAND(ID_TYPE_LOGIN, OnTypeLogin)
	ON_UPDATE_COMMAND_UI(ID_TYPE_LOGIN, OnUpdateTypeLogin)
	ON_COMMAND(ID_TYPE_LOGOUT, OnTypeLogout)
	ON_UPDATE_COMMAND_UI(ID_TYPE_LOGOUT, OnUpdateTypeLogout)
	ON_COMMAND(ID_CNTEST01, OnCntest01)
	ON_UPDATE_COMMAND_UI(ID_CNTEST01, OnUpdateCntest01)
	ON_COMMAND(ID_CNTEST02, OnCntest02)
	ON_UPDATE_COMMAND_UI(ID_CNTEST02, OnUpdateCntest02)
	ON_COMMAND(ID_CNTEST03, OnCntest03)
	ON_UPDATE_COMMAND_UI(ID_CNTEST03, OnUpdateCntest03)
	ON_COMMAND(ID_CNTEST04, OnCntest04)
	ON_UPDATE_COMMAND_UI(ID_CNTEST04, OnUpdateCntest04)
	ON_COMMAND(ID_ENTEST01, OnEntest01)
	ON_UPDATE_COMMAND_UI(ID_ENTEST01, OnUpdateEntest01)
	ON_COMMAND(ID_ENTEST02, OnEntest02)
	ON_UPDATE_COMMAND_UI(ID_ENTEST02, OnUpdateEntest02)
	ON_COMMAND(ID_ENTEST03, OnEntest03)
	ON_UPDATE_COMMAND_UI(ID_ENTEST03, OnUpdateEntest03)
	ON_COMMAND(ID_ENTEST04, OnEntest04)
	ON_UPDATE_COMMAND_UI(ID_ENTEST04, OnUpdateEntest04)
	ON_COMMAND(ID_KEYWORD_TEST, OnKeywordTest)
	ON_UPDATE_COMMAND_UI(ID_KEYWORD_TEST, OnUpdateKeywordTest)
	ON_COMMAND(ID_LOAD_QUESTION_FROM_FILE, OnLoadQuestionFromFile)
	ON_UPDATE_COMMAND_UI(ID_LOAD_QUESTION_FROM_FILE, OnUpdateLoadQuestionFromFile)
	ON_COMMAND(ID_KEYWORD_TEST01, OnKeywordTest01)
	ON_UPDATE_COMMAND_UI(ID_KEYWORD_TEST01, OnUpdateKeywordTest01)
	ON_COMMAND(ID_KEYWORD_TEST02, OnKeywordTest02)
	ON_UPDATE_COMMAND_UI(ID_KEYWORD_TEST02, OnUpdateKeywordTest02)
	ON_COMMAND(ID_KEYWORD_TEST03, OnKeywordTest03)
	ON_UPDATE_COMMAND_UI(ID_KEYWORD_TEST03, OnUpdateKeywordTest03)
	ON_COMMAND(ID_KEYWORD_TEST04, OnKeywordTest04)
	ON_UPDATE_COMMAND_UI(ID_KEYWORD_TEST04, OnUpdateKeywordTest04)
	ON_COMMAND(ID_KEYWORD_TEST05, OnKeywordTest05)
	ON_UPDATE_COMMAND_UI(ID_KEYWORD_TEST05, OnUpdateKeywordTest05)
	ON_COMMAND(ID_KEYWORD_TEST06, OnKeywordTest06)
	ON_UPDATE_COMMAND_UI(ID_KEYWORD_TEST06, OnUpdateKeywordTest06)
	ON_COMMAND(ID_KEYWORD_TEST_BASE, OnKeywordTestBase)
	ON_UPDATE_COMMAND_UI(ID_KEYWORD_TEST_BASE, OnUpdateKeywordTestBase)
	ON_COMMAND(ID_KEYWORD_TEST_NUMBER, OnKeywordTestNumber)
	ON_UPDATE_COMMAND_UI(ID_KEYWORD_TEST_NUMBER, OnUpdateKeywordTestNumber)
	ON_COMMAND(ID_CNTEST05, OnCntest05)
	ON_UPDATE_COMMAND_UI(ID_CNTEST05, OnUpdateCntest05)
	ON_COMMAND(ID_CNTEST06, OnCntest06)
	ON_UPDATE_COMMAND_UI(ID_CNTEST06, OnUpdateCntest06)
	ON_COMMAND(ID_CNKEYWORD, OnCnkeyword)
	ON_UPDATE_COMMAND_UI(ID_CNKEYWORD, OnUpdateCnkeyword)
	ON_COMMAND(ID_VIEW_SCORE, OnViewScore)
	ON_UPDATE_COMMAND_UI(ID_VIEW_SCORE, OnUpdateViewScore)
	ON_COMMAND(ID_VIEW_MAIN, OnViewMain)
	ON_UPDATE_COMMAND_UI(ID_VIEW_MAIN, OnUpdateViewMain)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTypeDoc construction/destruction

CTypeDoc::CTypeDoc()
{
	// TODO: add one-time construction code here
	m_pView				= NULL;
	m_pSocket			= NULL;
	m_bLogin			= FALSE;

	m_strHostName		="";

	m_strID				= "";
	m_strName			= "";

	m_strQuestion		= "";
	m_strQuestionInfo	= "";
	m_lTestTime			= 600;
	m_nInputLanguage	= 0;

	m_nMaxScoreID		= 0;
	m_ScoreList.RemoveAll();

	srand(time(NULL));
}

CTypeDoc::~CTypeDoc()
{
	if(m_pSocket!=NULL)
	{
		m_pSocket->Close();
		delete m_pSocket;
	}
	m_pView=NULL;
}

/////////////////////////////////////////////////////////////////////////////
// CTypeDoc serialization

void CTypeDoc::Serialize(CArchive& ar)
{
	int			i;
	SCOREDEF	sd;

	if (ar.IsStoring())
	{
		// TODO: add storing code here
		/*服务器信息*/
		ar<<m_strHostName;
		/*最后一个用户信息*/
		ar<<m_strID;
		ar<<m_strName;
		/*成绩信息*/
		ar<<m_nMaxScoreID;
		for(i=0;i<m_nMaxScoreID;i++)
		{
			sd=m_ScoreList[i];

			ar<<sd.strID;
			ar<<sd.strName;
			ar<<sd.nInputLanguage;
			ar<<sd.nRate;
			ar<<sd.nSpeed;
			ar<<sd.strTime;			
		}
	}
	else
	{
		// TODO: add loading code here
		/*服务器信息*/
		ar>>m_strHostName;
		/*最后一个用户信息*/
		ar>>m_strID;
		ar>>m_strName;
		/*成绩信息*/
		ar>>m_nMaxScoreID;
		m_ScoreList.RemoveAll();
		for(i=0;i<m_nMaxScoreID;i++)
		{
			ar>>sd.strID;
			ar>>sd.strName;
			ar>>sd.nInputLanguage;
			ar>>sd.nRate;
			ar>>sd.nSpeed;
			ar>>sd.strTime;
			m_ScoreList.Add(sd);
		}
	}
	
}

/////////////////////////////////////////////////////////////////////////////
// CTypeDoc diagnostics

#ifdef _DEBUG
void CTypeDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CTypeDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTypeDoc commands
////////////////////////////////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////////////////////////////
//载入试题
void CTypeDoc::LoadQuestion(LPCTSTR lpszQuestion, LPCTSTR lpszQuestionInfo, long lTestTime,int nInputLanguage)
{
	m_strQuestion=lpszQuestion;
	m_strQuestionInfo=lpszQuestionInfo;
	m_lTestTime=lTestTime;
	m_nInputLanguage=nInputLanguage;
	SetTitle(lpszQuestionInfo);
}

///////////////////////////////////////////////
//随机载入试题
void CTypeDoc::LoadRandQuestion(CString str, CString strTitle,int nLen, int n)
{
	CString strText;
	char	buf[1024];
	int		i;
	int		j;
	int		k;
	
	if(nLen>1024)
	{
		nLen=1024;
	}
	j=0;
	for(k=0;k<n;k++)//按规律产生k次
	{
		/*正序录入*/
		for(i=0;i<str.GetLength();i++)
		{
			buf[j++]=str.GetAt(i);
		}
		
		/*正序连续录入*/
		for(i=0;i<str.GetLength();i++)
		{
			buf[j++]=str.GetAt(i);
			buf[j++]=str.GetAt(i);
		}
	}

	/*随机产生*/
	for(i=j;i<nLen-1;i++)
	{
		buf[j++]=str.GetAt(rand()%str.GetLength());
	}
	buf[j]='\0';

	strText=buf;
	
	LoadQuestion(strText,strTitle);
	LoadQuestion(strText,strTitle,nLen,0);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////
void CTypeDoc::LoadQuestionFromResource(WORD resourseID, CString &strText)
{
	HMODULE hModule=GetModuleHandle(NULL);
	HRSRC	hr=FindResource(hModule,MAKEINTRESOURCE(resourseID),"TXT");

	if(hr==NULL)
	{
		return;
	}

	HGLOBAL hGlobal=LoadResource(hModule,hr);
	
	if(hGlobal==NULL)
	{
		FreeResource(hr);
		return;
	}

	LPVOID pv=(PSZ)LockResource(hGlobal);

	if(pv==NULL)
	{
		FreeResource(hr);
		return;
	}

	strText=(char*)pv;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
void CTypeDoc::LoadQuestionFromFile(CString strFileName)
{
	FILE* fPtr;
	
	if((fPtr=fopen(strFileName,"r"))==NULL)
	{
		return;
	}

	CString strText="";
	char c;
	while(!feof(fPtr))
	{
		c=fgetc(fPtr);
		strText.Format("%s%c",strText,c);
	}

	fclose(fPtr);
		
	if(strText.GetLength()!=0)
	{
		CString strTitle="无标题";
		if(strText.GetLength()>50 )
		{
			strTitle=strText.Left(50);
			int nPos=strTitle.Find('\n',0);
			if(nPos!=-1)
			{
				strTitle=strTitle.Left(nPos);
				strText=strText.Mid(nPos+1);
			}
			else
			{
				strTitle="无标题";
			}
		}

		int nInputLanguage=0;
		c=(UINT)strText.GetAt(0);
		nInputLanguage=(c>=(UINT)0xa1)?1:0;

		LoadQuestion(strText,strTitle,strText.GetLength()*5,nInputLanguage);
	}
	else
	{
		AfxMessageBox("您打开的是一个空文件!");
	}

}
///////////////////////////////////////////////////////////////////////////////////////////////////////

BOOL CTypeDoc::ConnectSocket(LPCTSTR lpszID, LPCTSTR lpszName, LPCTSTR lpszHostName, UINT nPort)
{
	if(m_pSocket)
	{//若已创建套接字
		m_pSocket->Close();
		delete m_pSocket;
		m_pSocket=NULL;
	}
	m_pSocket=new CUserSocket;
	m_pSocket->SetDoc(this);
	m_pSocket->Init();

	if(!m_pSocket->Create())
	{
		delete m_pSocket;
		m_pSocket=NULL;
		AfxMessageBox("套接安创建错误!");
		return FALSE;
	}

	while(!m_pSocket->Connect(lpszHostName,nPort))
	{
		if(AfxMessageBox("无法连接服务器!",MB_YESNO)==IDNO)
		{
			delete m_pSocket;
			m_pSocket=NULL;
			return FALSE;
		}
	}
	
	//连接成功时,发送用户信息
	CString strLocalName=CSocketInfo::GetLocalHostName();
	SendUserInfo(strLocalName,lpszID,lpszName);
	return TRUE;
}

void CTypeDoc::OnTypeLogin() 
{
	// TODO: Add your command handler code here
	CLoginDlg dlg;
	dlg.m_strID=m_strID;
	dlg.m_strName=m_strName;
	dlg.m_strHostName=m_strHostName;
	
	while(TRUE)
	{
		if(dlg.DoModal()!=IDOK)
		{
			return;
		}

		/*保存信息*/
		m_strID=dlg.m_strID;
		m_strName=dlg.m_strName;
		m_strHostName=dlg.m_strHostName;

		if(ConnectSocket(m_strID,m_strName,m_strHostName,PORT_DEFAULT))
		{
			return;
		}
	}
}

void CTypeDoc::ReceiveQuestion(CString strQuestion, CString strQuestionInfo, long lTestTime, int nInputLanguage)
{
	LoadQuestion(strQuestion,strQuestionInfo,lTestTime,nInputLanguage);
	SwitchToView(RUNTIME_CLASS(CNetTypeTestView));
}

void CTypeDoc::ReceiveSrvClose()
{
	m_pSocket->Close();
	CString str;
	str.LoadString(IDS_SRV_CLOSE);
	SetTitle(str);
	ShowUserInfo(str);
	ShowInfo("考试结束,还没做完的要重考!");
	
	ShowMainView();

	delete m_pSocket;
	m_pSocket=NULL;
	m_bLogin=FALSE;

}

void CTypeDoc::CloseSocket()
{
	if(m_pSocket==NULL)
		return;

	m_pSocket->Close();
	SetTitle("网上考试服务器已关闭");
	CString str;
	str.LoadString(ID_INDICATOR_USER_INFO);
	ShowUserInfo(str);
	delete m_pSocket;
	m_pSocket=NULL;

	m_bLogin=FALSE;
}

void CTypeDoc::ShowInfo(CString str)
{
	CStatusBar *pStatus=(CStatusBar *)AfxGetApp()->m_pMainWnd
		->GetDescendantWindow(AFX_IDW_STATUS_BAR);//取得窗口指针

	if(pStatus)
	{
		pStatus->SetPaneText(2,(LPCTSTR)str);
	}
}

void CTypeDoc::ShowUserInfo(CString str)
{
	CStatusBar *pStatus=(CStatusBar *)AfxGetApp()->m_pMainWnd
		->GetDescendantWindow(AFX_IDW_STATUS_BAR);//取得窗口指针

	if(pStatus){
		pStatus->SetPaneText(1,(LPCTSTR)str);
	}

}

void CTypeDoc::OnUpdateTypeLogin(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	if(m_bLogin)
	{
		pCmdUI->Enable(FALSE);
	}
	else
	{
		pCmdUI->Enable(TRUE);
	}
}



void CTypeDoc::ReceiveGetScore(int &nRateOfRight, int &nSpeedOfType)
{
	if(m_bLogin==TRUE)
	{
		nRateOfRight=((CNetTypeTestView*)m_pView)->GetRate();
		nSpeedOfType=((CNetTypeTestView*)m_pView)->GetSpeed();
	}
}

void CTypeDoc::ReceiveLoginFaild()
{
	m_bLogin=FALSE;//登陆失败

	CString str="用户验证失败!";
	ShowUserInfo(str);
}

void CTypeDoc::ReceiveLoginSuccess(CString strHostName,CString strID,CString strName)
{
	m_bLogin=TRUE;//登陆成功
	CString str;
	str.Format("客户机名称:%s  学号:%s  姓名:%s",strHostName,strID,strName);
	ShowUserInfo(str);
}

void CTypeDoc::SendUserInfo(CString strHostName, CString strID, CString strName)
{
	if(m_pSocket==NULL)
		return;

	m_pSocket->SendUserInfo(strHostName,strID,strName);
}

void CTypeDoc::SendScore(int nRate, int nSpeed, BOOL bSaveScore)
{
	if(m_bLogin!=TRUE)
		return ;

	if(bSaveScore==TRUE)
	{
		m_pSocket->SendSaveScore(nRate,nSpeed);

		CString str;
		SendUserLogout();//离开考试
		CloseSocket();//关闭服务
		str="考试结束,要重考请重新登陆!";
		ShowInfo(str);
	}
	else
	{
		m_pSocket->SendTypeScore(nRate,nSpeed);
	}
}

void CTypeDoc::SendUserLogout()
{
	if(m_bLogin)
	{
		m_pSocket->SendUserLogout();
		m_bLogin=FALSE;
	}
}


BOOL CTypeDoc::SwitchToView(CRuntimeClass *pNewViewClass)
{
	CFrameWnd* pMainWnd=(CFrameWnd*)AfxGetMainWnd();
	CView* pOldActiveView=pMainWnd->GetActiveView();

	if(pOldActiveView->IsKindOf(pNewViewClass))
	{
		pOldActiveView->OnInitialUpdate();
		return TRUE;
	}

	::SetWindowLong(pOldActiveView->m_hWnd,GWL_ID,0);

	CCreateContext context;
	context.m_pNewViewClass=pNewViewClass;
	context.m_pCurrentFrame=pMainWnd;
	context.m_pNewDocTemplate = NULL;
	context.m_pCurrentDoc=this;

	CView* pNewView=STATIC_DOWNCAST(CView,pMainWnd->CreateView(&context));
	
	if(pNewView!=NULL)
	{
		pNewView->ShowWindow(SW_SHOW);
		pNewView->OnInitialUpdate();
		pMainWnd->SetActiveView(pNewView);
		pMainWnd->RecalcLayout();

		m_pView=pNewView;

		pOldActiveView->DestroyWindow();

		return TRUE;
	}
	return FALSE;

}

void CTypeDoc::OnTypeLogout() 
{
	// TODO: Add your command handler code here
	SendUserLogout();
	CloseSocket();
	ShowMainView();
}

void CTypeDoc::OnUpdateTypeLogout(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(m_bLogin);
}

void CTypeDoc::OnLoadQuestionFromFile() 
{
	// TODO: Add your command handler code here
	char szFilter[] = "文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*||";
	
	CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY,szFilter);
	if(dlg.DoModal()==IDOK)
	{
		LoadQuestionFromFile(dlg.GetPathName());
		SwitchToView(RUNTIME_CLASS(CTypeView));
	}	
}

void CTypeDoc::OnUpdateLoadQuestionFromFile(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}


void CTypeDoc::OnKeywordTestBase() 
{
	// TODO: Add your command handler code here
	//CString str="asdfjkl;";
	CString str="fjdksla;asdfjkl;";
	CString strTitle="8个基准键练习";
	int nLen=256;
	LoadRandQuestion(str,strTitle,nLen*2,3);
	SwitchToView(RUNTIME_CLASS(CKeyWordView));
}

void CTypeDoc::OnUpdateKeywordTestBase(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

////////////////////////////////////////////////////////////////
void CTypeDoc::OnKeywordTest01() 
{
	// TODO: Add your command handler code here
	//CString str="asdfghjkl;";
	CString str="ghfjdksla;asdfghjkl;";
	CString strTitle="中排键(asdfghjkl;)练习";
	int nLen=256;
	LoadRandQuestion(str,strTitle,nLen*2,3);
	SwitchToView(RUNTIME_CLASS(CKeyWordView));
}

void CTypeDoc::OnUpdateKeywordTest01(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnKeywordTest02() 
{
	// TODO: Add your command handler code here
	CString str="ftjyfrjudekiswloaq;pqwertyuiop";
	CString strTitle="上排键(qwertyuiop)练习";
	int nLen=256;
	LoadRandQuestion(str,strTitle,nLen*2,2);
	SwitchToView(RUNTIME_CLASS(CKeyWordView));
}

void CTypeDoc::OnUpdateKeywordTest02(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnKeywordTest03() 
{
	// TODO: Add your command handler code here
	CString str="fbjnfvjmdck,sxl.az;/zxcvbnm,./";
	CString strTitle="下排键(zxcvbnm,./)练习";
	int nLen=256;
	LoadRandQuestion(str,strTitle,nLen*2,2);
	SwitchToView(RUNTIME_CLASS(CKeyWordView));
}

void CTypeDoc::OnUpdateKeywordTest03(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnKeywordTest04() 
{
	// TODO: Add your command handler code here
	CString str="fjfgjhftjyfrjudekiswloaqpfbjnfvjmdcksxlazabcdefghijklmnopqrstuvwxyz";
	CString strTitle="26个小写英文字母练习";
	int nLen=512;
	LoadRandQuestion(str,strTitle,nLen*2,2);
	SwitchToView(RUNTIME_CLASS(CKeyWordView));
}

void CTypeDoc::OnUpdateKeywordTest04(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnKeywordTest05() 
{
	// TODO: Add your command handler code here
	CString str="aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ";
	CString strTitle="26个大写英文字母练习";
	int nLen=256;
	LoadRandQuestion(str,strTitle,nLen*2,2);
	SwitchToView(RUNTIME_CLASS(CKeyWordView));
}

void CTypeDoc::OnUpdateKeywordTest05(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnKeywordTest06() 
{
	// TODO: Add your command handler code here
	CString str=",<.>;:'\"/?\\|[]{}`~1!2@3#4$5%6^7&8*9(0)-_=+";
	CString strTitle="英文标点符号练习";
	int nLen=256;
	LoadRandQuestion(str,strTitle,nLen*2,2);
	SwitchToView(RUNTIME_CLASS(CKeyWordView));
}

void CTypeDoc::OnUpdateKeywordTest06(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnKeywordTestNumber() 
{
	// TODO: Add your command handler code here
	CString str="f5j6f4j7d3k8s2l91;0";
	CString strTitle="10个数字键(0-9)练习";
	int nLen=256;
	LoadRandQuestion(str,strTitle,nLen*2,3);
	SwitchToView(RUNTIME_CLASS(CKeyWordView));
}

void CTypeDoc::OnUpdateKeywordTestNumber(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnKeywordTest() 
{
	// TODO: Add your command handler code here
	CString str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ,.//;:<>\'\"\\|~!@#$%^&*()_+-=123456780{[]}";
	CString strTitle="键盘综合练习";
	int nLen=256;
	LoadRandQuestion(str,strTitle,nLen*2,0);
	SwitchToView(RUNTIME_CLASS(CKeyWordView));
}

void CTypeDoc::OnUpdateKeywordTest(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

////////////////////////////////////////////////////////////////

void CTypeDoc::OnEntest01() 
{
	// TODO: Add your command handler code here
	CString strText;
	CString strTitle;

	strText.LoadString(IDS_ENTEST01);
	strTitle="英文练习一";
	LoadQuestion(strText,strTitle,strText.GetLength()*2,0);

	SwitchToView(RUNTIME_CLASS(CTypeView));
}

void CTypeDoc::OnUpdateEntest01(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnEntest02() 
{
	// TODO: Add your command handler code here
	CString strText;
	CString strTitle;

	strText.LoadString(IDS_ENTEST02);
	strTitle="英文练习二";
	LoadQuestion(strText,strTitle,strText.GetLength()*2,0);

	SwitchToView(RUNTIME_CLASS(CTypeView));
}

void CTypeDoc::OnUpdateEntest02(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnEntest03() 
{
	// TODO: Add your command handler code here
	CString strText;
	CString strTitle;

	strText.LoadString(IDS_ENTEST03);
	strTitle="英文练习三";
	LoadQuestion(strText,strTitle,strText.GetLength()*2,0);

	SwitchToView(RUNTIME_CLASS(CTypeView));
}

void CTypeDoc::OnUpdateEntest03(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnEntest04() 
{
	// TODO: Add your command handler code here
	CString strText;
	CString strTitle;

	strText.LoadString(IDS_ENTEST04);
	strTitle="英文练习四";
	LoadQuestion(strText,strTitle,strText.GetLength()*2,0);

	SwitchToView(RUNTIME_CLASS(CTypeView));
}


void CTypeDoc::OnUpdateEntest04(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

/////////////////////////////////////////////////////////////////////
void CTypeDoc::OnCnkeyword() 
{
	// TODO: Add your command handler code here
	CString strText;
	CString strTitle;

	strText.LoadString(IDS_CNKEYWORD);
	
	strTitle="智能ABC键名字";
	LoadQuestion(strText,strTitle,strText.GetLength()*5,1);
	SwitchToView(RUNTIME_CLASS(CTypeView));
}

void CTypeDoc::OnUpdateCnkeyword(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

/////////////////////////////////////////////////////////
void CTypeDoc::OnCntest01() 
{
	// TODO: Add your command handler code here
	CString strText;
	CString strTitle;
	
	LoadQuestionFromResource(IDR_HOT_WORD,strText);
	
	strText=strText.Left(1200);

	strTitle="常用词练习一";
	LoadQuestion(strText,strTitle,strText.GetLength()*5,1);
	SwitchToView(RUNTIME_CLASS(CTypeView));
}

void CTypeDoc::OnUpdateCntest01(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnCntest02() 
{
	// TODO: Add your command handler code here
	CString strText;
	CString strTitle;

	LoadQuestionFromResource(IDR_HOT_WORD,strText);
	
	strText=strText.Mid(1200,1200);

	strTitle="常用词练习二";
	LoadQuestion(strText,strTitle,strText.GetLength()*5,1);
	SwitchToView(RUNTIME_CLASS(CTypeView));
}

void CTypeDoc::OnUpdateCntest02(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnCntest03() 
{
	// TODO: Add your command handler code here
	CString strText;
	CString strTitle;

	LoadQuestionFromResource(IDR_HOT_WORD,strText);
	
	strText=strText.Mid(2400,1200+2);

	strTitle="常用词练习三";
	LoadQuestion(strText,strTitle,strText.GetLength()*5,1);

	SwitchToView(RUNTIME_CLASS(CTypeView));
}

void CTypeDoc::OnUpdateCntest03(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnCntest04() 
{
	// TODO: Add your command handler code here
	CString strText;
	CString strTitle;

	LoadQuestionFromResource(IDR_HOT_WORD,strText);
	
	strText=strText.Mid(3600+2,1200);

	strTitle="常用词练习四";
	LoadQuestion(strText,strTitle,strText.GetLength()*5,1);
	SwitchToView(RUNTIME_CLASS(CTypeView));
}

void CTypeDoc::OnUpdateCntest04(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnCntest05() 
{
	// TODO: Add your command handler code here
	CString strText;
	CString strTitle;

	LoadQuestionFromResource(IDR_HOT_WORD,strText);
	
	strText=strText.Mid(4800+2,1200);

	strTitle="常用词练习五";
	LoadQuestion(strText,strTitle,strText.GetLength()*5,1);
	SwitchToView(RUNTIME_CLASS(CTypeView));
}

void CTypeDoc::OnUpdateCntest05(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnCntest06() 
{
	// TODO: Add your command handler code here
	CString strText;
	CString strTitle;

	LoadQuestionFromResource(IDR_HOT_WORD,strText);

	strText=strText.Mid(6400+2);

	strTitle="常用词练习六";
	LoadQuestion(strText,strTitle,strText.GetLength()*5,1);
	SwitchToView(RUNTIME_CLASS(CTypeView));
}

void CTypeDoc::OnUpdateCntest06(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::AddScore(CString strID,CString strName, int nRate, int nSpeed)
{
	SCOREDEF sd;
	sd.strID=strID;
	sd.strName=strName;
	sd.nInputLanguage=m_nInputLanguage;
	sd.nRate=nRate;
	sd.nSpeed=nSpeed;
	CTime tm;
	sd.strTime=tm.GetCurrentTime().Format("%Y年%m月%d日 %H:%M:%S");
	m_ScoreList.Add(sd);
	m_nMaxScoreID++;

	SetModifiedFlag();
}

/*保存成绩*/
void CTypeDoc::SaveScore(int nRate, int nSpeed)
{
	CInputDlg	dlg;
	CString		str;
	dlg.m_strID		= m_strID;
	dlg.m_strName	= m_strName;
	dlg.m_nRate		= nRate;
	dlg.m_nSpeed	= nSpeed;
	
	if(dlg.DoModal()==IDOK)
	{
		m_strID=dlg.m_strID;
		m_strName=dlg.m_strName;

		AddScore(m_strID,m_strName,nRate,nSpeed);
	}

}

void CTypeDoc::ShowScoreView()
{
	SwitchToView(RUNTIME_CLASS(CScoreView));
	CString str;
	str.LoadString(IDS_TITLE);
	SetTitle(str);
}

void CTypeDoc::OnViewScore() 
{
	// TODO: Add your command handler code here
	ShowScoreView();
}

void CTypeDoc::ShowMainView()
{
	SwitchToView(RUNTIME_CLASS(CMainView));
	CString str;
	str.LoadString(IDS_TITLE);
	SetTitle(str);
}

void CTypeDoc::OnUpdateViewScore(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

void CTypeDoc::OnViewMain() 
{
	// TODO: Add your command handler code here
	ShowMainView();
}

void CTypeDoc::OnUpdateViewMain(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(!m_bLogin);
}

BOOL CTypeDoc::SaveModified() 
{
	// TODO: Add your specialized code here and/or call the base class
	if(IsModified())
	{
		OnFileSave();
	}
	return TRUE;
	//return CDocument::SaveModified();
}


BOOL CTypeDoc::OnNewDocument() 
{
	// TODO: Add your specialized code here and/or call the base class
	CString str;
	str.LoadString(IDS_TITLE);
	SetTitle(str);

	return CDocument::OnNewDocument();
}